package com.sujeet.activity.tracker.web.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sujeet.activity.tracker.web.*;
import javax.servlet.http.HttpSession;

import com.sujeet.activity.tracker.model.Activity;
import com.sujeet.activity.tracker.model.access.*;
/**
 * Servlet implementation class Show
 */
public class Show extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Show() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    public void init() throws ServletException {
    	CreateDummyData.create();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	    ActivityCrudUtils activityCrudUtils = new ActivityCrudUtils();
	    List<Activity> activities = activityCrudUtils.getAllActivityEntries();
	    request.setAttribute("activityList", activities);
	    request.getRequestDispatcher("WEB-INF/Activities.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	
//	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//	    HttpSession session = request.getSession(true);
//	    // Set the session valid for 5 secs
//	    // session.setMaxInactiveInterval(5);
//	    response.setContentType("text/plain");
//	    PrintWriter out = response.getWriter();
//	    if (session.isNew()) {
//	    }
//	    out.println("\n");
//	    CreateSampleData createSampleData = new CreateSampleData();
//	    out.println(createSampleData.getAllActivitiesText());
//	}
}
